package com.kuang.demo.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kuang.demo.bo.gh.CreateBrandBO;
import com.kuang.demo.bo.gh.UpdateBrandBO;
import com.kuang.demo.dto.BrandDTO;
import com.kuang.demo.mapper.StoreMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by 郭浩 on 2020/11/1 17:15
 */
@Service
public class StoreServiceImpl implements StoreService {
    @Autowired
    StoreMapper storeMapper;

    @Override
    //page, limit, id, name,sort, order
    public Map<String, Object> queryBrandList(Integer page, Integer limit, Integer id, String name, String sort, String order) {

        PageHelper.startPage(page,limit);
        List<BrandDTO> brandDTOList = storeMapper.queryBrandList(id,name, sort,order);

        //获得查询总数
        PageInfo<BrandDTO> brandDTOPageInfo = new PageInfo<>(brandDTOList);
        Long i = brandDTOPageInfo.getTotal();
        int total = i.intValue();
        Map<String,Object> brandinfo = new HashMap();
        brandinfo.put("brandList",brandDTOList);
        brandinfo.put("total",total);
        return brandinfo;
    }

    @Override
    public void createBrand(CreateBrandBO createBrandBO) {
        storeMapper.createBrand(createBrandBO);
    }

    @Override
    public void updateBrand(UpdateBrandBO updateBrandBO) {
        storeMapper.updateBrand(updateBrandBO);
    }

    @Override
    public void deleteBrand(UpdateBrandBO deleteBrandBO) {
        storeMapper.deleteBrand(deleteBrandBO);
    }

}
